
// Tables-DataTables.js
// ====================================================================
// This file should not be included in your project.
// This is just a sample how to initialize plugins or components.
//
// - ThemeOn.net -



$(window).on('load', function() {
    // DATA TABLES
    // =================================================================
    // Require Data Tables
    // -----------------------------------------------------------------
    // http://www.datatables.net/
    // =================================================================

    $.fn.DataTable.ext.pager.numbers_length = 5;
    // Row selection (single row)
    // -----------------------------------------------------------------
    var rowSelection = $('#customer-alert-table').DataTable({
        "processing": true,
        serverSide: true,
        searchable: false,
        //lengthChange:true,
        paging: true,
        //"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
        pageLength: 20,
        ajax: {
            url: "/admin/customer/alert",
            type: 'post',
            dataSrc: 'data'
        },
        columns: [
            {data: 'id'},
            {data: 'name'},
            {data: 'phone'},
            {data: 'alertDate'}
        ],
        "responsive": true,
        "language": {
            "paginate": {
              "previous": '<i class="demo-psi-arrow-left"></i>',
              "next": '<i class="demo-psi-arrow-right"></i>'
            }
        },
        "dom": '<"toolbar">frtip',
        "rowCallback": function (row, data, index) {
            $('td:eq(0)', row).html('<a target="_blank" href="/admin/customer/edit/' + data["id"] + '">' + data["id"] + '</a>');
            $('td:eq(1)', row).html(data["name"] + "(" + data["company"] + ")");


            var alertDate = data["alertDate"];
            var diff = getDiffOfNow(alertDate);
            if (diff < 1) {
                $('td:eq(3)', row).html("<span class='label label-danger'> " + diff + "天 </span> " + timeStamp2String(alertDate));
            } else if (diff == 1) {
                $('td:eq(3)', row).html("<span class='label label-purple'> " + diff + "天 </span> " + timeStamp2String(alertDate));
            } else if (diff == 2) {
                $('td:eq(3)', row).html("<span class='label label-warning'> " + diff + "天 </span> " + timeStamp2String(alertDate));
            } else {
                $('td:eq(3)', row).html("<span class='label label-info'> " + diff + "天 </span> " + timeStamp2String(alertDate));

            }
        }
    });

});
